<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>售卖中的商品列表</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			loadTable();
			$('#dlg').dialog('close');
			
		});
		
		function loadTable(){
			$('#dg').datagrid({
				rownumbers:true,
				singleSelect:true,
				pagination:true,
				pageSize:20,
				pageList:[10,20,30,50,100],
		 		url:'${pageContext.request.contextPath }/goods/goodslist',
	    		columns:[[
					{field:'goods_id',title:'商品编号',align:'center',width:80},
					{field:'goods_name',title:'商品名称',align:'center',width:200},
					{field:'app_name',title:'APP展示名',align:'center',width:200},
					{field:'goods_kindname',title:'商品类别',align:'center',width:100},
					{field:'store_num',title:'销售库存',align:'center',width:100},
					{field:'sale_num',title:'已售数量',align:'center',width:100},
					{field:'sale_price',title:'商品价格',align:'center'},
					{field:'limit_num',title:'限购数量',width:100,align:'center'},
					{field:'operation',title:'操作选项',width:280,align:'center',formatter: function (value, row, index) {
						var str = '<a href="javascript:edit('+row.goods_id+')" name="edit" class="easyui-linkbutton" ></a>';					
						str=str+' | <a href="javascript:putaway('+row.goods_id+')" name="down"  class="easyui-linkbutton" ></a>';
						str=str+' | <a href="javascript:editGoodsinfo('+row.goods_id+')" name="editGoods"  class="easyui-linkbutton" ></a>';
						return str;
					}}
	 			]],
				onLoadSuccess:function(data){  
			        $("a[name='edit']").linkbutton({text:'修改售价库存',plain:true,iconCls:'icon-my-manage'});
			        $("a[name='down']").linkbutton({text:'下架',plain:true,iconCls:'icon-my-manage'});
			         $("a[name='editGoods']").linkbutton({text:'编辑信息',plain:true,iconCls:'icon-edit'});
				}
			});
		}
		
		function putaway(goods_id){
            $.post("${pageContext.request.contextPath}/goods/putAway",{goods_id:goods_id,goods_status:2},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">商品下架失败，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','商品下架成功！');
						$('#dg').datagrid('reload'); 
					}
				},"text");
        }
		
		function showImg(imgUrl){
			$('#dlg').dialog('open');
			var image=document.getElementById("stationImg");
			var src="${pageContext.request.contextPath }"+imgUrl;
			image.setAttribute("src",src );
		}
		
		function edit(goods_id){
	//		show("${pageContext.request.contextPath}/goods/storepriceview/"+goods_id,"修改商品信息");
			location.href="${pageContext.request.contextPath}/goods/storepriceview/"+goods_id+"-1";
		}
		
		function editGoodsinfo(goods_id){
			show("${pageContext.request.contextPath}/goods/editGoodsinfoBefore/"+goods_id,"商品信息修改");
		}

		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}

	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
	</style>
  </head>
  
  <body>
    <table id="dg" title="售卖中的商品列表"></table>
    <div id="dlg" class="easyui-dialog" title="站长头像查看" style="width:270px;height:390px;max-width:800px;padding:10px" data-options="
			onResize:function(){
				$(this).dialog('center');
			}">
			<img id="stationImg" src="" width="220" height="320"/>
	</div>
  </body>
</html>
